import {http} from '@/plugins/net.js'
import role from "@/views/auth/role";

/**
 * 分页查询数据
 * @param searchData
 * @param currPage
 * @param pageSize
 * @returns {Promise<AxiosResponse<any>>}
 */
export const list = async (searchData,currPage,pageSize) => {
    let url = '/menu/list?1=1'
    if (currPage) {
        url += `&currentPage=${currPage}`
    }
    if (pageSize) {
        url += `&pageSize=${pageSize}`
    }
    if (searchData && searchData.parentId) {
        url += `&parentId=${searchData.parentId}`
    }
    if (searchData && searchData.name) {
        url += `&name=${searchData.name}`
    }
    if (searchData && searchData.type) {
        url += `&type=${searchData.type}`
    }
    if (searchData && searchData.isLink) {
        url += `&isLink=${searchData.isLink}`
    }

    const res = await http(url,'get',null)
    if (res) {
        return res
    }
}

/**
 * 获取所有目录
 * @returns {Promise<AxiosResponse<any>>}
 */
export const listAllDirectory = async  () => {
    let url = `/menu/list/directory`
    const res = await http(url,'get',null)
    if (res) {
        return res
    }
}

/**
 * 检查menuId 是否已经存在
 * @param menuId
 * @returns {Promise<AxiosResponse<any>>}
 */
export const checkIdExist = async (menuId) => {
    let url = `/menu/check/id?menuId=${menuId}`
    const res = await http(url,'get',null)
    if (res) {
        return res
    }
}

/**
 * 添加菜单
 * @param menu
 * @returns {Promise<AxiosResponse<any>>}
 */
export const addMenu = async (menu) => {
    let url = `/menu/add`
    const res = await http(url,'post',menu)
    if (res) {
        return res
    }
}

/**
 * 获取所有权限
 * @returns {Promise<AxiosResponse<any>>}
 */
export const getAuthTree = async () => {
    let url = '/menu/auth/tree'
    const res = await  http(url,'get',null)
    if (res) {
        return res
    }
}


